package com.xing.Customer.Action;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.xing.Customer.Entity.Customer;
import com.xing.Customer.Service.CustomerService;

import net.sf.json.JSONObject;

/**
*@author xingxing
*@version 
*@time 2017年10月19日 下午11:19:28 
*class explain：
*/
@Controller
@Scope("prototype")
public class CustomerAction {
	private HttpServletResponse response = ServletActionContext.getResponse();//为了得到response,响应
	private HttpServletRequest request = ServletActionContext.getRequest();//为了得到request,请求
	
	@Autowired
	CustomerService customerService;
	/**
	 * @author xingxing
	 * @date 2017-10-19 23:22:51
	 * @return 
	 * 跳转展示页
	 */
	public String Page() {
		return "cuspage";
	}
	
	
	/**
	 * @author xingxing
	 * @date 2017-10-19 23:23:57
	 * @throws IOException 
	 * datagrid，访问的地址，然后返回数据，
	 * 用的是ajax的异步访问的形式
	 */
	public void CusList() throws IOException {
		String search=request.getParameter("search")==null?"":request.getParameter("search");
		int total=customerService.query(search);
		String pageno=request.getParameter("page")==null?"1":request.getParameter("page");
		String rows=request.getParameter("rows")==null?"1":request.getParameter("rows");
		List<Customer> list=(List<Customer>) customerService.listpage(pageno, rows,search);
		Map map = new HashMap();
		map.put("total", total);
		map.put("rows", list);
		JSONObject jsonObject= JSONObject.fromObject(map);
		System.out.println("JSONOBJECT:"+jsonObject.toString());
		response.getWriter().write(jsonObject.toString());
	}
	
	
	
	private Customer customer;
	public Customer getCustomer() {
		return customer;
	}
	public void setCustomer(Customer customer) {
		this.customer = customer;
	}
	
}
